//
//  HomeViewModel.m
//  Futures
//
//  Created by Cheng on 2017/6/21.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "HomeViewModel.h"
#import "NetWork.h"
#import "CycleModel.h"
#import "QuoteModel.h"
#import "NSObject+Extension.h"

@implementation HomeViewModel


+ (void)requestCycleData:(void(^)(NSArray *cycleArray))block
{
    NSMutableArray *array = [NSMutableArray array];
    [Network requestNoRowDataMethod:GET WithUrl:NETWORK_CYCLEAD_DATA parameters:@{@"version":@"2.300"} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSArray *data = responseObject[@"data"];
        for (NSDictionary *dict in data) {
            CycleModel *cycleModel = [[CycleModel alloc] initWithDict:dict];
            [array addObject:cycleModel];
        }
        block(array);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

+ (void)requestQuoteList:(void(^)(NSArray *quoteList))block
{
    NSMutableArray *array = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat:@"%@?%@",URL_QUOTE_LIST,@"symbol=CLQ7&exchange=NYMEX&symbol=ESU7&exchange=GLOBEX&symbol=HSIN17&exchange=HKFE&symbol=NGQ7&exchange=NYMEX"];
    [Network requestDataMethod:GET WithUrl:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSArray *arr = responseObject;
        for (NSDictionary *dict in arr) {
            QuoteModel *quoteModel = [[QuoteModel alloc] initWithDict:dict];
            [array addObject:quoteModel];
        }
        block(array);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

@end
